package com.crane.app.web.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.validation.Valid;

import com.crane.common.core.dto.MultiResponse;
import com.crane.common.core.utils.BaseContextHandler;
import com.crane.oss.app.bean.req.AppQueryStudentClassCourseReq;
import com.crane.oss.sports.XunFeiAppApiService;
import com.crane.oss.xunfei.req.QueryAppAnalysisStudentClassCourseReq;
import com.crane.oss.xunfei.resp.ApiListResponse;
import com.crane.oss.xunfei.resp.AppAnalysisStudentClassCourseResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.crane.common.core.dto.SingleResponse;
import com.crane.common.framework.utils.BeanUtil;
import com.crane.oss.enums.GradeEnum;
import com.crane.oss.school.bean.request.QueryStudentReq;
import com.crane.oss.school.bean.resp.AppStudentResp;
import com.crane.oss.school.bean.resp.ClassesInfoResp;
import com.crane.oss.school.bean.resp.AppStudentResp.StudentInfo;
import com.crane.oss.school.bean.resp.StudentResp;
import com.crane.oss.school.service.ClassesInfoService;
import com.crane.oss.school.service.StudentService;
import com.crane.oss.web.BaseBusinessController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@Api(value = "SportsPlanController", tags = { "运动处方" })
@RestController
@RequestMapping("/app/sportsplan")
public class SportsPlanController extends BaseAppController {

    @Autowired
    StudentService studentService;

	@Autowired
	ClassesInfoService classesInfoService;


	@ApiOperation(value = "学生列表", notes = "学生列表")
	@ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryStudentReq")
	@PostMapping("/list")
	public SingleResponse<AppStudentResp> list(@RequestBody @Valid QueryStudentReq request) {
		request.setPartyId(getPartyId());
		request.setPageSize(10000);
		IPage<StudentResp> page = studentService.queryList(request);

		AppStudentResp studentResp = new AppStudentResp();
		List<StudentInfo> list = new ArrayList<StudentInfo>();
		for (StudentResp student : page.getRecords()) {
			StudentInfo info = studentResp.new StudentInfo();
			BeanUtil.copyProperties(student, info);
			list.add(info);
		}

		ClassesInfoResp classesInfoResp = classesInfoService.queryClassesInfo(request.getClassId());

		studentResp.setClassInfo(GradeEnum.getGradeEnum(request.getGrade())+classesInfoResp.getClassName());
		studentResp.setStudentList(list);
		return SingleResponse.of(studentResp);
	}




}
